package com.atg.ai_agent.rag.advisor;
import com.atg.ai_agent.rag.LoveContextualQueryAugmenter;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;
/*
author: atg
time: 2025/10/3 19:07
*/



/**
 * 自定义RAG增强器工厂
 */
public class LoveAppRagCustomAdvisorFactory {



    public static Advisor createLoveAppRagCustomAdvisorFactory(VectorStore vectorStore, String status){

        Filter.Expression expression = new FilterExpressionBuilder()
                .eq("status", status).build();// 过滤条件

        // 创建文档增强器
        VectorStoreDocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder()
                .vectorStore(vectorStore)  // 在向量存储中检索文档
                .filterExpression(expression) // 过滤条件
                .similarityThreshold(0.5) // 相似度阈值
                .topK(3) // 返回的文档数量
                .build();

        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(documentRetriever) // 设置文档检索器
                .queryAugmenter(LoveContextualQueryAugmenter.create()) // 查询增强器
                .build();
    }



}
